package kuzmenkov.oip.controller.applet;

import java.awt.FlowLayout;

import javax.swing.JCheckBox;

/**
 * The class is a boolean UI component. It can be used for to input boolean values.
 * 
 * @author Michael Kuzmenkov
 * 
 */
public class BooleanUIC extends ParamUIC {

	private static final long serialVersionUID = -2666493826633442560L;
	//private Logger log  = Logger.getLogger(BooleanUIC.class.getName());
	protected JCheckBox component;


	public BooleanUIC(Param parameter) {
		super(parameter);
		init();
	}

	public Object getValue() {
		boolean val = component.isSelected();
		return new Boolean(val);
	}

	private void init() {
		Param param = getParam();
		String name = param.getName();
		String desc = param.getDescription();
		boolean isResult = param.isResult();
		Boolean defVal = new Boolean (param.getDefaultValue());

		component = new JCheckBox (name, defVal.booleanValue());
		
		component.setToolTipText(truncateString(desc,MAX_TIP_LENGTH));
		component.setEnabled(!isResult);

		setLayout(new FlowLayout(FlowLayout.LEFT));

		add(component);

	}

	/**
	 * Sets the value into the component.
	 */
	public void setValue(Object value) {
		boolean val = ((Boolean)value).booleanValue();
		component.setSelected(val);
	}

}
